﻿#region Copyright and License Notice
// Copyright (C)2010-2012 - Rob Levine and other contributors
// http://configgen.codeplex.com
// 
// This file is part of ConfigGen.
// 
// ConfigGen is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// 
// ConfigGen is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License and 
// the GNU Lesser General Public License along with ConfigGen.  
// If not, see <http://www.gnu.org/licenses/>.
#endregion
using System;
using ConfigGen.Core.SettingsLoader;
using ConfigGen.Core.TemplateLoader;
using Moq;
using NUnit.Framework;

namespace ConfigGen.Core.Tests
{
    [TestFixture]
    public class ConfigurationFilesGeneratorTests
    {
        //[Test]
        //public void Ctor_NullSettingsLoaderThrows()
        //{
        //    var mockRepository = new MockRepository(MockBehavior.Strict);
        //    var mockTemplateLoader = mockRepository.Create<ITemplateLoader>();
        //    var mockMachineConfigurationSettingCollectionFilter = mockRepository.Create<IMachineConfigurationSettingCollectionFilter>();
        //    var mockReadOnlyContainer = mockRepository.Create<IReadOnlyContainer>();
            
        //    var exception = Assert.Throws<ArgumentNullException>(
        //        () => new ConfigurationFilesGenerator(
        //                 // null,
        //                  mockTemplateLoader.Object,
        //                  mockMachineConfigurationSettingCollectionFilter.Object,
        //                  mockReadOnlyContainer.Object),
        //        "null should raise exception");
        //    Assert.AreEqual("settingsLoader", exception.ParamName, "incorrect param name");
        //    mockRepository.VerifyAll();
        //}

        [Test]
        public void Ctor_NullTemplateLoaderThrows()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);
            var mockDefaultSettingsCombiner = mockRepository.Create<IDefaultSettingsCombiner>();
            var mockMachineConfigurationSettingCollectionFilter = mockRepository.Create<IMachineConfigurationSettingCollectionFilter>();
            var mockReadOnlyContainer = mockRepository.Create<IReadOnlyContainer>();

            var exception = Assert.Throws<ArgumentNullException>(
                () => new ConfigurationFilesGenerator(
                           mockDefaultSettingsCombiner.Object,
                          null,
                          mockMachineConfigurationSettingCollectionFilter.Object,
                          mockReadOnlyContainer.Object),
                "null should raise exception");
            Assert.AreEqual("templateLoader", exception.ParamName, "incorrect param name");
            mockRepository.VerifyAll();
        }


        [Test]
        public void Ctor_NullConfigurationFilesGeneratorHelperThrows()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);
            var mockDefaultSettingsCombiner = mockRepository.Create<IDefaultSettingsCombiner>();
            var mockTemplateLoader = mockRepository.Create<ITemplateLoader>();
            var mockReadOnlyContainer = mockRepository.Create<IReadOnlyContainer>();

            var exception = Assert.Throws<ArgumentNullException>(
               () => new ConfigurationFilesGenerator(
                      mockDefaultSettingsCombiner.Object,
                             mockTemplateLoader.Object,
                         null,
                         mockReadOnlyContainer.Object),
               "null should raise exception");
            Assert.AreEqual("machineConfigurationSettingCollectionFilter", exception.ParamName, "incorrect param name");
            mockRepository.VerifyAll();
        }

        [Test]
        public void Ctor_NullReadOnlyContainerThrows()
        {
            var mockRepository = new MockRepository(MockBehavior.Strict);
            var mockDefaultSettingsCombiner = mockRepository.Create<IDefaultSettingsCombiner>();
            var mockTemplateLoader = mockRepository.Create<ITemplateLoader>();
            var mockMachineConfigurationSettingCollectionFilter = mockRepository.Create<IMachineConfigurationSettingCollectionFilter>();

            var exception = Assert.Throws<ArgumentNullException>(
               () => new ConfigurationFilesGenerator(
                         mockDefaultSettingsCombiner.Object,
                         mockTemplateLoader.Object,
                         mockMachineConfigurationSettingCollectionFilter.Object,
                         null),
               "null should raise exception");
            Assert.AreEqual("readOnlyContainer", exception.ParamName, "incorrect param name");
            mockRepository.VerifyAll();
        }

        //TODO: Plenty more tests here!
    }
}
